package net.zoneland.knowledge.dao;

import net.zoneland.knowledge.model.OpLog;
import org.apache.ibatis.jdbc.SQL;

public class OpLogSqlProvider {

    public String insertSelective(OpLog record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("AITK_OPLOG");
        
        if (record.getId() != null) {
            sql.VALUES("ID", "#{id,jdbcType=VARCHAR}");
        }
        
        if (record.getSystemId() != null) {
            sql.VALUES("SYSTEM_ID", "#{systemId,jdbcType=VARCHAR}");
        }
        
        if (record.getToken() != null) {
            sql.VALUES("TOKEN", "#{token,jdbcType=VARCHAR}");
        }
        
        if (record.getVisitType() != null) {
            sql.VALUES("VISIT_TYPE", "#{visitType,jdbcType=VARCHAR}");
        }
        
        if (record.getUserId() != null) {
            sql.VALUES("USER_ID", "#{userId,jdbcType=VARCHAR}");
        }
        
        if (record.getSessionId() != null) {
            sql.VALUES("SESSION_ID", "#{sessionId,jdbcType=VARCHAR}");
        }
        
        if (record.getRequestId() != null) {
            sql.VALUES("REQUEST_ID", "#{requestId,jdbcType=VARCHAR}");
        }
        
        if (record.getParentRequestId() != null) {
            sql.VALUES("PARENT_REQUEST_ID", "#{parentRequestId,jdbcType=VARCHAR}");
        }
        
        if (record.getComponentId() != null) {
            sql.VALUES("COMPONENT_ID", "#{componentId,jdbcType=VARCHAR}");
        }
        
        if (record.getCategoryList() != null) {
            sql.VALUES("CATEGORY_LIST", "#{categoryList,jdbcType=VARCHAR}");
        }
        
        if (record.getQuestionId() != null) {
            sql.VALUES("QUESTION_ID", "#{questionId,jdbcType=VARCHAR}");
        }
        
        if (record.getRequestUrl() != null) {
            sql.VALUES("REQUEST_URL", "#{requestUrl,jdbcType=VARCHAR}");
        }
        
        if (record.getRequestParam() != null) {
            sql.VALUES("REQUEST_PARAM", "#{requestParam,jdbcType=VARCHAR}");
        }
        
        if (record.getElementId() != null) {
            sql.VALUES("ELEMENT_ID", "#{elementId,jdbcType=VARCHAR}");
        }
        
        if (record.getAction() != null) {
            sql.VALUES("ACTION", "#{action,jdbcType=VARCHAR}");
        }
        
        if (record.getDevice() != null) {
            sql.VALUES("DEVICE", "#{device,jdbcType=VARCHAR}");
        }
        
        if (record.getReferer() != null) {
            sql.VALUES("REFERER", "#{referer,jdbcType=VARCHAR}");
        }
        
        if (record.getUserAgent() != null) {
            sql.VALUES("USER_AGENT", "#{userAgent,jdbcType=VARCHAR}");
        }
        
        if (record.getOs() != null) {
            sql.VALUES("OS", "#{os,jdbcType=VARCHAR}");
        }
        
        if (record.getBrowser() != null) {
            sql.VALUES("BROWSER", "#{browser,jdbcType=VARCHAR}");
        }
        
        if (record.getIp() != null) {
            sql.VALUES("IP", "#{ip,jdbcType=VARCHAR}");
        }
        
        if (record.getUaDevice() != null) {
            sql.VALUES("UA_DEVICE", "#{uaDevice,jdbcType=VARCHAR}");
        }
        
        if (record.getCreateTime() != null) {
            sql.VALUES("CREATE_TIME", "#{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getUserName() != null) {
            sql.VALUES("USER_NAME", "#{userName,jdbcType=VARCHAR}");
        }

        if (record.getCmpDn() != null) {
            sql.VALUES("CMP_DN", "#{cmpDn,jdbcType=VARCHAR}");
        }

        if (record.getCmpName() != null) {
            sql.VALUES("CMP_NAME", "#{cmpName,jdbcType=VARCHAR}");
        }
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(OpLog record) {
        SQL sql = new SQL();
        sql.UPDATE("AITK_OPLOG");
        
        if (record.getSystemId() != null) {
            sql.SET("SYSTEM_ID = #{systemId,jdbcType=VARCHAR}");
        }
        
        if (record.getToken() != null) {
            sql.SET("TOKEN = #{token,jdbcType=VARCHAR}");
        }
        
        if (record.getVisitType() != null) {
            sql.SET("VISIT_TYPE = #{visitType,jdbcType=VARCHAR}");
        }
        
        if (record.getUserId() != null) {
            sql.SET("USER_ID = #{userId,jdbcType=VARCHAR}");
        }
        
        if (record.getSessionId() != null) {
            sql.SET("SESSION_ID = #{sessionId,jdbcType=VARCHAR}");
        }
        
        if (record.getRequestId() != null) {
            sql.SET("REQUEST_ID = #{requestId,jdbcType=VARCHAR}");
        }
        
        if (record.getParentRequestId() != null) {
            sql.SET("PARENT_REQUEST_ID = #{parentRequestId,jdbcType=VARCHAR}");
        }
        
        if (record.getComponentId() != null) {
            sql.SET("COMPONENT_ID = #{componentId,jdbcType=VARCHAR}");
        }
        
        if (record.getCategoryList() != null) {
            sql.SET("CATEGORY_List = #{categoryList,jdbcType=VARCHAR}");
        }
        
        if (record.getQuestionId() != null) {
            sql.SET("QUESTION_ID = #{questionId,jdbcType=VARCHAR}");
        }
        
        if (record.getRequestUrl() != null) {
            sql.SET("REQUEST_URL = #{requestUrl,jdbcType=VARCHAR}");
        }
        
        if (record.getRequestParam() != null) {
            sql.SET("REQUEST_PARAM = #{requestParam,jdbcType=VARCHAR}");
        }
        
        if (record.getElementId() != null) {
            sql.SET("ELEMENT_ID = #{elementId,jdbcType=VARCHAR}");
        }
        
        if (record.getAction() != null) {
            sql.SET("ACTION = #{action,jdbcType=VARCHAR}");
        }
        
        if (record.getDevice() != null) {
            sql.SET("DEVICE = #{device,jdbcType=VARCHAR}");
        }
        
        if (record.getReferer() != null) {
            sql.SET("REFERER = #{referer,jdbcType=VARCHAR}");
        }
        
        if (record.getUserAgent() != null) {
            sql.SET("USER_AGENT = #{userAgent,jdbcType=VARCHAR}");
        }
        
        if (record.getOs() != null) {
            sql.SET("OS = #{os,jdbcType=VARCHAR}");
        }
        
        if (record.getBrowser() != null) {
            sql.SET("BROWSER = #{browser,jdbcType=VARCHAR}");
        }
        
        if (record.getIp() != null) {
            sql.SET("IP = #{ip,jdbcType=VARCHAR}");
        }
        
        if (record.getUaDevice() != null) {
            sql.SET("UA_DEVICE = #{uaDevice,jdbcType=VARCHAR}");
        }
        
        if (record.getCreateTime() != null) {
            sql.SET("CREATE_TIME = #{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getUserName() != null) {
            sql.VALUES("USER_NAME", "#{userName,jdbcType=VARCHAR}");
        }

        if (record.getCmpDn() != null) {
            sql.VALUES("CMP_DN", "#{cmpDn,jdbcType=VARCHAR}");
        }

        if (record.getCmpName() != null) {
            sql.VALUES("CMP_NAME", "#{cmpName,jdbcType=VARCHAR}");
        }
        sql.WHERE("ID = #{id,jdbcType=VARCHAR}");
        
        return sql.toString();
    }
}